<!doctype html> 
<html> 
<head> 
    <meta charset="utf-8"> 
    <title></title> 
</head>
<body>

<script type="text/javascript">
onload = function(){
	aInput = document.getElementsByTagName('input');
	function show(leo){
		return function(){
			alert(leo)
		}

	};
	for(var i = 0;i < aInput.length;i++){
		aInput[i].onclick = show(i)

	}

}

</script>
</body>
<input type='button' value='0'>
<input type='button' value='1'>
<input type='button' value='2'>
</html>